package basic

import (
	"fmt"
)

/*寻找最长不含有重复字符的字串
abcabcbb ---> abc
bbbbb	   ---> b
pwwkew   ---> wke
*/
func findStr(str string) int {
	lastOccurred := make(map[rune]int)
	start := 0
	maxLength := 0

	for i, v := range []rune(str) {
		if lastIndex, ok := lastOccurred[v]; ok && lastIndex >= start {
			start = lastIndex + 1
		}
		if i-start+1 > maxLength {
			maxLength = i - start + 1
		}
		lastOccurred[v] = i
	}
	return maxLength
}

func main() {
	string1 := "abcabkcbb"
	fmt.Println(findStr(string1))

	/*m1 := map[string]string{
		"今天": "today",
		"你好": "hello",
	}
	//m2 := make(map[string]int) // m2 == empty
	//var m3  map[string]int 		   // m3 == nil

	//遍历
	for k,v := range m1{
		fmt.Println(k,v)
	}
	// 判断元素存不存在
	if str,ok := m1["你好a"]; ok{
		//fmt.Println(str)
	}else{
		fmt.Println("key does not exist")
	}

	// 删除
	if _,ok := m1["今天"]; ok{
		//delete(m1,"今天")
	}
	*/
}
